package org.holynite.fieldmanage.managed.model

import org.holynite.fieldmanage.ejbs.CustomerTypeManagement
import org.holynite.fieldmanage.entities.CustomerType

import javax.annotation.PostConstruct
import javax.ejb.EJB
import javax.faces.bean.ManagedBean
import javax.faces.bean.ViewScoped

/**
 * Created by midnite on 15/1/31.
 */
@ManagedBean
@ViewScoped
class CustomerTypesBean implements Serializable {
    List<CustomerType> types

    @EJB(beanName = "customerTypeControl")
    CustomerTypeManagement ctService

    CustomerTypesBean() {
        types = []
    }

    @PostConstruct
    void initiate() {
        types = ctService.searchTypes("")
    }

    void reloadCustomerTypes(String keyword) {
        types = ctService.searchTypes(keyword)
    }

    CustomerType findCustomerType(String type) {
        types.find { it.customerTypeId.equals(type) }
    }
}
